package com.azt.provider.impl;

import com.azt.api.pojo.TestEnquiryAI;
import com.azt.api.service.TestEnquiryService;
import com.azt.model.page.Pagination;
import com.azt.provider.mapper.TestEnquiryMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 询价测试
 * @author 张栋  2016年9月6日上午9:58:25
 */
@Service
@Transactional
public class TestEnquiryServiceImpl implements TestEnquiryService {

	@Autowired
	private TestEnquiryMapper enquiryDao;

	@Override
	public Pagination getTestEnquiryPage(int pageno, int pagesize, Map<String, String> searchMap) {
		Page<Object> startPage = PageHelper.startPage(pageno, pagesize);
		List<TestEnquiryAI> list = enquiryDao.getTestEnquiryAIByPage(searchMap);
		Pagination  p = new Pagination(startPage,list);
		return p;
	}

	@Override
	public TestEnquiryAI getTestEnquiryById(Integer id) {
		return enquiryDao.selectOne(new TestEnquiryAI(id));
//		TestEnquiryAI ai = enquiryDao.getTestEnquiryAIById(id);
//		return ai;
	}

	@Override
	public int updateTestEnquiry(TestEnquiryAI enquiry) {
		return enquiryDao.updateByPrimaryKey(enquiry);
	}


	@Override
	public int deleteTestEnquiry(TestEnquiryAI enquiry) {
		if(enquiry != null) {
			return enquiryDao.delete(enquiry);
		}
		return 0;
	}

	@Override
	public void saveTestEnquiry(TestEnquiryAI ai) {
		enquiryDao.insert(ai);
	}

}
